%% MAE 531 Project - Software main
% This is the main file (the optimizaiton driver).

% Last modification by Rodney on

% Written collectively by group members Lamar Julien, Rodney Metoyer, and
% Lisa Worthington.
% License information for any code not written by the group is embedded in
% the respective functions. All software written by the authors listed
% above is not intended for release, but may be released under an
% open license only.

% Call Structure
    % main.m
        % objectiveMain.m
            % sun_position.m
            % advanceTime.m

% Clear the workspace
clear all; close all; clc;

%% Simulation Set-up
% The simulation will run with parameters values that are set-up in the
% function objectiveMain.m. If you want to change any of those parameters
% (dates, simulation length, etc.) you must change them in that function.
% See the function for more details.

% % Define the design vector and give it a start point
% fieldLength = [50,50,50,50,50,50,50,50,50,50.0]; % length of the field
% fieldWidth  = [50,50,50,50,50,50,50,50,50,50.0]; % width of the field
% %panelLength = [1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5];   % length of a panel
% %panelWidth  = [1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5];   % Width of a panel
% panelLength = [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0];   % length of a panel
% panelWidth  = [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0];   % Width of a panel
% panelSpace  = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0];   % Space between panels in the east-west direction
% 
% for i=1:1:length(panelSpace)
% designVector(i,:) = [fieldLength(i), fieldWidth(i), panelLength(i), panelWidth(i), panelSpace(i)];
% 
% [energyJoules(i), numPanels(i)] = objectiveMain(designVector(i,:));
% energyKWhr(i) = energyJoules(i)*2.77777778E-7;
% energyDensity(i) = energyKWhr(i)/(numPanels(i)*panelLength(i)*panelWidth(i)); %(KWhr/m^2/day)
% end
% 
% plot(panelSpace, energyKWhr,'ok','MarkerFaceColor','k')

fieldLength = 20; % length of the field
fieldWidth  = 30; % width of the field
panelLength = 0.75;   % length of a panel
panelWidth  = 0.5;   % Width of a panel
panelSpace  = 0.2;   % Space between panels in the east-west direction

x0 = [fieldLength; fieldWidth; panelLength; panelWidth; panelSpace];
Lb = [0; 0; 0; 0; 0];
Ub = [100; 100; 100; 100; 100];

[designVec, energyKWh, exitFlag, output] = fmincon('minObjectiveMain2',...
    x0,[],[],[],[],Lb,Ub,'constraintMain');